package org.tloss.web.spring;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class BeanFactory implements ApplicationContextAware {

	private ApplicationContext applicationContext;
	private static BeanFactory beanFactory = null;
	private BeanFactory(){
		
	}
	public static synchronized BeanFactory getBeanFactory(){
		if(beanFactory == null){
			beanFactory = new BeanFactory();
		}
		return beanFactory;
	}

	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		this.applicationContext = applicationContext;
	}

	@SuppressWarnings("unchecked")
	public <T> T getBean(String beanName, Class<T> c) {
		return (T) applicationContext.getBean(beanName);
	}
	public static void main(String[] args) {
		
	}

}
